<?php
declare (strict_types = 1);

namespace app\api\model\v1;

use think\Model;

/**
 * @mixin \think\Model
 */
class AuthRule extends AppModel
{
    //


    //菜单类型
    const TYPE_ONE = 1;
    const TYPE_TWO = 2;

    public static $is_type = array(
        self::TYPE_ONE => '系统功能',
        self::TYPE_TWO => '用户功能',
    );


    const OPEN_ONE = 1;
    const OPEN_TWO = 0;

    public static $is_open = array(
        self::OPEN_ONE => '启用',
        self::OPEN_TWO => '禁用'
    );

    const IS_MENU_ZERO = 0; //是否为菜单 （不是菜单）
    const IS_MENU_ONE = 1; //是菜单(默认)

    public static $is_menu = array(
        self::IS_MENU_ZERO => '不是菜单',
        self::IS_MENU_ONE => '是菜单'
    );

    /**
     * @param $array
     * @param int $pid
     * @User: 刘海龙
     * @Date: 2021/9/22
     * @Time: 17:51
     * @return array
     * 递归树
     */
    public static function sortMenu($array, $pid = 0)
    {
        $arr = array();
        foreach ($array as $v) {

            if ($v['pid'] == $pid) {
                $temp = self::sortMenu($array, $v['id']);
                //判断是否存在子数组
                if ($temp) {
                    $v['child'] = $temp;
                }

                $arr[] = $v;
            }
        }
        return $arr;
    }

}
